package com.ruoyi.web.controller.warehouseManagement;

import java.util.Date;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.InventoryLossReport;
import com.ruoyi.system.service.IInventoryLossReportService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 库存报损 Controller
 *
 * @author ruoyi
 * @date 2025-06-01
 */
@Api(tags="库存报损")
@RestController
@RequestMapping("/system/inventoryLossReport")
public class InventoryLossReportController extends BaseController
{
    @Autowired
    private IInventoryLossReportService inventoryLossReportService;

    /**
     * 通过报损单号，报损仓库名称,报损类型,报损开始时间和报损结束时间查询库存报损列表
     */
    @ApiOperation("通过报损单号，报损仓库名称，报损类型，报损开始时间和报损结束时间查询库存报损列表")
    @PreAuthorize("@ss.hasPermi('system:report:list')")
    @GetMapping("/list")
    public TableDataInfo list(@RequestParam (required = false) String lossReportNumber, @RequestParam (required = false) String lossWarehouseName, @RequestParam (required = false) String lossType, @RequestParam (required = false) Date lossStartTime,@RequestParam (required = false) Date lossEndTime,
                              @RequestParam (required = false) String lossEmployee)
    {
        startPage();
        List<InventoryLossReport> list = inventoryLossReportService.selectInventoryLossReportListByConditions(lossReportNumber,lossWarehouseName,lossType,lossStartTime,lossEndTime,lossEmployee);
        return getDataTable(list);
    }

    /**
     * 导出库存报损列表
     */
    @ApiOperation("导出库存报损列表")
    @PreAuthorize("@ss.hasPermi('system:report:export')")
    @Log(title = "库存报损", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, @RequestParam (required = false) String lossReportNumber,@RequestParam (required = false) String lossWarehouseName,@RequestParam (required = false) String lossType,@RequestParam (required = false) Date lossStartTime,@RequestParam (required = false) Date lossEndTime,
                       @RequestParam (required = false) String lossEmployee)
    {
        List<InventoryLossReport> list = inventoryLossReportService.selectInventoryLossReportListByConditions(lossReportNumber,lossWarehouseName,lossType,lossStartTime,lossEndTime,lossEmployee);
        ExcelUtil<InventoryLossReport> util = new ExcelUtil<InventoryLossReport>(InventoryLossReport.class);
        util.exportExcel(response, list, "库存报损数据");
    }

    /**
     * 通过id获取库存报损详细信息
     */
    @ApiOperation("通过id获取库存报损详细信息")
    @PreAuthorize("@ss.hasPermi('system:report:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(inventoryLossReportService.selectInventoryLossReportById(id));
    }

    /**
     * 新增库存报损
     */
    @ApiOperation("新增库存报损")
    @PreAuthorize("@ss.hasPermi('system:report:add')")
    @Log(title = "库存报损", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody InventoryLossReport inventoryLossReport)
    {
        return toAjax(inventoryLossReportService.insertInventoryLossReport(inventoryLossReport));
    }

    /**
     * 修改库存报损
     */
    @ApiOperation("修改库存报损")
    @PreAuthorize("@ss.hasPermi('system:report:edit')")
    @Log(title = "库存报损", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody InventoryLossReport inventoryLossReport)
    {
        return toAjax(inventoryLossReportService.updateInventoryLossReport(inventoryLossReport));
    }

    /**
     * 通过id批量删除库存报损信息
     */
    @ApiOperation("通过id批量删除库存报损信息")
    @PreAuthorize("@ss.hasPermi('system:report:remove')")
    @Log(title = "库存报损", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(inventoryLossReportService.deleteInventoryLossReportByIds(ids));
    }
}
